package com.mx.restful.view.icon;

import com.intellij.openapi.util.IconLoader;
import com.mx.restful.beans.HttpMethod;
import com.mx.restful.configuration.RestfulSetting;
import com.intellij.ui.IconManager;
import icons.MxIcons;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

import static com.intellij.openapi.util.IconLoader.getIcon;

/**
 * @Author: mengxiang.
 * @Date: 2020/6/22.
 * @Time: 11:37 上午.
 * @Description:
 */
public class Icons {

    public static final Icon SERVICE = load("/icons/service.png");

    @NotNull
    public static Icon load(@NotNull String path) {
        return IconManager.getInstance().getIcon(path, Icons.class);
    }

    /**
     * 获取方法对应的图标
     *
     * @param method 请求类型
     * @return icon
     */
    @NotNull
    public static Icon getMethodIcon(HttpMethod method) {
        return getMethodIcon(method, false);
    }

    public static Icon getMethodIcon(HttpMethod method, boolean selected) {
        String iconTypeClass = RestfulSetting.getInstance().getAppSetting().iconTypeClass;
        IconType iconType = IconTypeManager.getInstance(iconTypeClass);
        if (selected) {
            return iconType.getSelectIcon(method);
        }
        return iconType.getDefaultIcon(method);
    }
}
